package app.auto.runner.base.utility.base;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;

import app.auto.AndroidInstance;
import app.auto.runner.base.Util;
import app.auto.runner.base.intf.FunCallback;
import app.auto.runner.base.utility.ShareAlert;
import dalvik.system.DexFile;


public class DexUtil extends AndroidInstance {

    public List<String> getClassName(String packageName, boolean inncludeInner) {
        return getClassNamePrivate(packageName, inncludeInner);
    }

    private List<String> getClassNamePrivate(String packageName, boolean inncludeInner) {
        List<String> classNameList = new ArrayList<String>();

        Context ctx = this.getContext();
        try {
            DexFile df = new DexFile(ctx.getPackageCodePath());//通过DexFile查找当前的APK中可执行文件
            Enumeration<String> enumeration = df.entries();//获取df中的元素  这里包含了所有可执行的类名 该类名包含了包名+类名的方式
            while (enumeration.hasMoreElements()) {//遍历
                String className = (String) enumeration.nextElement();
                if (!inncludeInner) {
                    if (className.contains("$")) {
                        continue;
                    }
                }
                if (className.contains(packageName)) {//在当前所有可执行的类里面查找包含有该包名的所有类
                    classNameList.add(className);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return classNameList;
    }


    @Override
    public AndroidInstance use(Object mp, Object... p) {

        return null;
    }
}
